/***************************************************
  Defs.h
****************************************************/

#ifndef _defs_
#define _defs_

#define NULL 0x0

#define byte unsigned char
#define word short int
#define dword int

typedef int size_t;
typedef short int ssize_t;
typedef enum{FALSE=0, TRUE} bool;


/*#define FALSE   0;
#define TRUE    1;
*/
#define OS_PID 0
#define GETCBUFFER  80

/* Constantes para paging */
#define CANT_PAGES      1024
#define PAGE_SIZE       4096
#define STACK_LENGTH    0x400


/* Flags para derechos de acceso de los segmentos */
#define ACS_PRESENT     0x80            /* segmento presente en memoria */
#define ACS_CSEG        0x18            /* segmento de codigo */
#define ACS_DSEG        0x10            /* segmento de datos */
#define ACS_READ        0x02            /* segmento de lectura */
#define ACS_WRITE       0x02            /* segmento de escritura */
#define ACS_IDT         ACS_DSEG
#define ACS_INT_386     0x0E            /* Interrupt GATE 32 bits */
#define ACS_INT         ( ACS_PRESENT | ACS_INT_386 )


#define ACS_CODE        (ACS_PRESENT | ACS_CSEG | ACS_READ)
#define ACS_DATA        (ACS_PRESENT | ACS_DSEG | ACS_WRITE)
#define ACS_STACK       (ACS_PRESENT | ACS_DSEG | ACS_WRITE)


/* Definicion de colores  */

#define BLACK       0x00
#define BLUE        0x01
#define GREEN       0x02
#define CYAN        0x03
#define RED         0x04
#define MAGENTA     0x05
#define BROWN       0x06
#define LGREY       0x07
#define DGREY       0x08
#define LBLUE       0x09
#define LGREEN      0x0A
#define LCYAN       0x0B
#define LRED        0x0C
#define LMAGENTA    0x0D
#define LBROWN      0x0E
#define WHITE       0x0F

/* Ctes para sched */
#define SCHED_LOTTERY   0
#define SCHED_PRIORITY  1

#define PRIORITY_RATIO  2
#define MAX_PRIORITY    4


#pragma pack (1)                /* Alinear las siguiente estructuras a 1 byte */

/* Descriptor de segmento */
typedef struct
{
    word limit, base_l;
    byte base_m, access, attribs,  base_h;
} DESCR_SEG;


/* Descriptor de interrupcion */
typedef struct
{
    word offset_l, selector;
    byte cero, access;
    word offset_h;
} DESCR_INT;

/* IDTR  */
typedef struct
{
    word  limit;
    dword base;
} IDTR;


typedef struct
{
    int caps_lock;
    int num_lock;
    int scroll_lock;
    int rShift;
    int lShift;
    int rAlt;
    int lAlt;
    int rCtrl;
    int lCtrl;
    int dieresis;
    int accent;
    int enhanced;
}tipoFlags;

typedef struct
{
    unsigned short *    address;
    unsigned short      offset;
    int                 heigth;
    int                 width;
    unsigned short      bGColor;
    unsigned short      textColor;
}screenManager;


#define TTY_BUFFER_SIZE     128

typedef struct
{
    int buffer[TTY_BUFFER_SIZE];
    int first;
    int last;
    int cant;
}ttyBuffer;

#define TTY_CANT            8
typedef struct
{
    screenManager screen;
    int movimiento;
    ttyBuffer buffer;
}TTY;

typedef struct
{
    int EDI, ESI, EBP, ESP, EBX, EDX, ECX, EAX,  EIP, CS, EFLAGS;
    void*retaddr;
    int argc;
    char** argv;
} STACK_FRAME;

#define MAX_PROCESS_NAME    20
#define MAX_PROC            20

typedef struct PROCESS
{
    int pid;
    char name [MAX_PROCESS_NAME];
    int priority;
    int tty;
    int foreground;
    int lastCalled;
    int sleep;
    int blocked;
    int parent;
    int ESP;
    int free;
    int stackstart;
    int stacksize;
    int stackpages; 		//cantidad paginas usadas por el stack
    int heap_page;
    int stack_page;
    int next_free;
} PROCESS;

#endif

